package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyMdPsfymx;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyMdPsfymxMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdCaiwuParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdPsfymxParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyMdPsfymxResult;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyMdSfcResult;
import cn.stylefeng.guns.sys.modular.system.model.result.OrderDataResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdPsfymxService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 配送费用明细 服务实现类
 * </p>
 *
 * @author 
 * @since 2021-10-25
 */
@Service
public class BtyMdPsfymxServiceImpl extends ServiceImpl<BtyMdPsfymxMapper, BtyMdPsfymx> implements BtyMdPsfymxService {

    @Override
    public void add(BtyMdPsfymxParam param){
        BtyMdPsfymx entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyMdPsfymxParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyMdPsfymxParam param){
        BtyMdPsfymx oldEntity = getOldEntity(param);
        BtyMdPsfymx newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyMdPsfymxResult findBySpec(BtyMdPsfymxParam param){
        return null;
    }

    @Override
    public List<BtyMdPsfymxResult> findListBySpec(BtyMdPsfymxParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyMdPsfymxParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BtyMdPsfymxParam param){
        return param.getBtyMdPsfymxId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyMdPsfymx getOldEntity(BtyMdPsfymxParam param) {
        return this.getById(getKey(param));
    }

    private BtyMdPsfymx getEntity(BtyMdPsfymxParam param) {
        BtyMdPsfymx entity = new BtyMdPsfymx();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

    /**
     * 配送费用明细
     * @param param
     * @return
     */
    @Override
    public List<BtyMdPsfymxResult> findAllPsfymx(BtyMdCaiwuParam param) {

        List<BtyMdPsfymxResult> list = this.baseMapper.findAllPsfymx(param);
        return list;
    }

    @Override
    public LayuiPageInfo findAllSfc(BtyMdCaiwuParam param) {
        Page pageContext = LayuiPageFactory.defaultPage();
        IPage page = this.baseMapper.findAllSfc(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<BtyMdSfcResult> findSfcDate(BtyMdCaiwuParam param) {
        List<BtyMdSfcResult> list = this.baseMapper.findSfcDate(param);
        return list;
    }

}
